﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace AntsCode.StorageClientExtensions.Helpers
{
    public class ExpressionUtil
    {
        public static MethodCallExpression FindMethodCall(Expression expression, string[] names)
        {
            MethodCallExpression method = null;

            if (expression.NodeType == ExpressionType.Call)
            {
                MethodCallExpression m = (MethodCallExpression)expression;

                if (names.FirstOrDefault(x => x == m.Method.Name) != null)
                {
                    method = m;
                }
                else
                {
                    method = FindMethodCall(m.Arguments[0], names);
                }
            }

            return method;
        }
    }
}
